<extend name="Public/base"/>

<block name="body">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li>
                <a href="{:U('Admin/Index/index')}">首页 </a>
                <i class="fa fa-circle"></i>
            </li>
            <li>
                <span>矿池概览</span>
            </li>
        </ul>
        <div class="page-toolbar">
            <include file="Public/_addTo"/>
        </div>
    </div>

    <!-- 标题栏 -->
    <div class="main-title">
        <h2>矿池概览</h2>
    </div>
    <div class="content">
        <div class="row">
            <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="info-box">
                    <span class="info-box-icon bg-aqua"><i class="fa fa-houzz"></i></span>

                    <div class="info-box-content">
                        <span class="info-box-text">当前运行矿机</span>
                        <span class="info-box-number">{$pool.total_user_miner}</span>
                    </div>
                    <!-- /.info-box-content -->
                </div>
                <!-- /.info-box -->
            </div>
            <!-- /.col -->
            <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="info-box">
                    <span class="info-box-icon bg-red"><i class="fa fa-bitcoin"></i></span>

                    <div class="info-box-content">
                        <span class="info-box-text">累计产出SID</span>
                        <span class="info-box-number">{$pool.production_pool}</span>
                    </div>
                    <!-- /.info-box-content -->
                </div>
                <!-- /.info-box -->
            </div>
            <!-- /.col -->

            <!-- fix for small devices only -->
            <div class="clearfix visible-sm-block"></div>

            <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="info-box">
                    <span class="info-box-icon bg-red"><i class="fa fa-bitcoin"></i></span>

                    <div class="info-box-content">
                        <span class="info-box-text">昨日产出SID</span>
                        <span class="info-box-number">{$pool.yesterday_out}</span>
                    </div>
                    <!-- /.info-box-content -->
                </div>
                <!-- /.info-box -->
            </div>
            <!-- /.col -->
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="box box-info">
                    <div class="box-header ui-sortable-handle" style="cursor: move;">
                        <i class="fa fa-houzz"></i>
                        <h3 class="box-title">挖矿控制台</h3>
                    </div>
                    <div class="box-body">
                        <div class="progress-container">

                        </div>
                    </div>
                    <div class="box-footer clearfix">
                        <button type="button" class="pull-right btn btn-primary start-mining btn-mining"
                        <eq name="data.status" value="off">style="display:block;"</eq>
                        >开始挖矿
                        <i class="fa fa-arrow-circle-right"></i></button>
                        <button type="button" class="pull-right btn btn-default stop-mining disabled btn-mining" disabled
                        <eq name="data.status" value="on">style="display:block;"</eq>
                        >挖矿中</button>
                        <button type="button" class="pull-right btn btn-default disable-mining disabled btn-mining" disabled
                        <eq name="data.status" value="disable">style="display:block;"</eq>
                        >今日已产币</button>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="box box-info">
                    <div class="box-header ui-sortable-handle" style="cursor: move;">
                        <i class="fa fa-houzz"></i>
                        <h3 class="box-title">当前操作中的管理员</h3>
                    </div>
                    <div class="box-body">
                        <ul>
                            <volist name="ip_pool" id="val">
                            <li>{$val}-{$val|getIpAddressName}(最近活跃:{$val|getLastActivityTime})</li>
                            </volist>
                        </ul>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <!-- 数据列表 -->
</block>
<block name="style">
    <style>
        .btn-mining{
            display: none;
        }
    </style>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script src="__PUBLIC__/zui/js/zui.min.js"></script>
    <script type="text/javascript">
        //导航高亮
        highlight_subnav("{:U('SidToken/mining')}");

        $(function () {
            miningProgress();
            setInterval(function () {
                miningProgress();
            }, 10000);
        });
        //start mining
        $(".start-mining").click(function () {
            var r = confirm("是否确认开始");
            if (r) {
                console.log("start mining");
                $(".start-mining").hide();
                $(".stop-mining").show();
                let startUrl = "/admin/sidToken/startMining";
                $.get(startUrl, function (data, status) {
                    miningProgress();
                    alert("数据: " + data + "\n状态: " + status);
                });
            }

        });
        $(".stop-mining").click(function () {
            var r = confirm("是否确认结束");
            if (r) {
                console.log("stop mining");
                $(".start-mining").show();
                $(".stop-mining").hide();
                // $.get("/try/ajax/demo_test.php",function(data,status){
                //     alert("数据: " + data + "\n状态: " + status);
                // });
            }

        });

        //矿池状态读取
        function miningProgress() {
            let url = "{:U('SidToken/poolConsole')}";
            $(".progress-container").load(url);
        }
    </script>
</block>